import axios from 'axios'
import qs from 'qs'

// 创建一个包含默认配置的axios实例
const axiosInstance = axios.create({
  withCredentials: true, // 确保跨域请求时携带cookie
  headers: {
    'Content-Type': 'application/json',
    'X-Requested-With': 'XMLHttpRequest'
  }
})

/** 添加评论 */
export const createReview = (params: object) => {
    return axiosInstance.post('/api/review/add.do', qs.stringify(params), {
        headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
    })
}
/** 根据酒店获取评价列表 */
export const getReviewsByHotel = (hotelName: string) => {
    return axiosInstance.get('/api/review/listByHotel.do', { params: { hotelName } })
}
/** 查询单个评论 */
export const getReviewByTime = (reviewTime: string) => {
    return axiosInstance.get('/api/review/get.do', { params: { reviewTime } })
}
/** 查询全部评论 */
export const getReviewList = () => {
    return axiosInstance.get('/api/review/listAll.do')
}
/** 更新评论 */
export const updateReview = (params: object) => {
    return axiosInstance.post('/api/review/update.do', qs.stringify(params), {
        headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
    })
}
/** 删除评论 */
export const deleteReview = (params: {userId: string, hotelName: string, reviewTime: string}) => {
    return axiosInstance.post('/api/review/delete.do', qs.stringify(params), {
        headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
    })
}
